In [10]:
from IPython.display import clear_output #import a module function that lets use clear the output
from random import randint #imports a module function that lets use pick random numbers
from time import sleep #imports a module function that will pause the code for a certain amount of time

answers = [ "As I see it, yes.", #All of the magic 8 ball's answers
            "Ask again later.",
            "Better not tell you now.",
            "Cannot predict now.",
            "Concentrate and ask again.",
            "Don’t count on it.",
            "It is certain.",
            "It is decidedly so.",
            "Most likely.",
            "My reply is no.",
            "My sources say no.",
            "Outlook not so good.",
            "Outlook good.",
            "Reply hazy, try again.",
            "Signs point to yes.",
            "Very doubtful.",
            "Without a doubt.",
            "Yes.",
            "Yes",
            "definitely.",
            "You may rely on it.",] 

transcript = open("Magic 8 ball conversation", "w") #Opens the transcript and lets us write on it

def magic8Ball(): #Magic 8 ball function to use the magic 8 ball

    clear_output #Clears the output

    pause = randint(0,5) #Picking a random number between 0 and 5 and setting ti a variable called pause

    question = input("Ask a  yes or no question. Or think one really hard. The magic 8 ball knows you. -->") #Ask the user to type a question and store it as question

    print("Thinking...") #Prints thinking for detial
    
    sleep(pause) #Waits the random number stored in pause

    response  = answers[randint(0,21)] #pciks a random answer out of 20 answers to store in response 

    clear_output() #Clears the output

    if question == "": #if the user does not put in a question
        print("This question is kept a secret") #We tell them the question is kept a secret because the 8 ball can read their mind
    else: #If they did type a question
        print(question) #We remind them their question

    transcript.write("\n") #Writes a space
    transcript.write(question) #Writes the user's question
    transcript.write("\n") #Writes a space
    transcript.write(response) #Writes the 8 ball's answer
    transcript.write("\n") #Writes a space
    
    print(response) #Print the magic 8 ball's answer

    menu() #Puts them into the menu so they can use the magic 8 ball again or exit

def menu(): #A function so the user can the magic 8 ball or exit
    
    choice = input("Would you like to use the magic 8 ball? Type y for yes. Type n for no -->") #asking the user for a choice of y or n

    if choice == "y": #If they choice y
        magic8Ball() #We call the 8 ball function so they can use the magic 8 ball
    elif choice == "n": #If they choice n
        transcript
        print("Have a magical or awful day. The choice is yours.") #We leave a goodbye message
        transcript.close() #Closes the transcript
    else: #If they did not put y or n
        print("Not a choice") #We tell them not a choice
        input("Press enter") #Wait for them to press enter
        menu() #Restart the menu
    
if __name__ == "__main__":   #__main__ is created by the prgroam automatically  and this if statement prevents librarys from taking control
    menu() #Puts the user into the menu so they can use the magic 8 ball again or exit
Is planet 9 real? Not talking about Pluto.
Without a doubt.
Have a magical or awful day. The choice is yours.
In [ ]: